3175. 找到连续赢 K 场比赛的第一位玩家
为保证权益,题目请参考 3175. 找到连续赢 K 场比赛的第一位玩家(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def findWinningPlayer(self, skills: List[int], k: int) -> int:
n = len(skills)
if n <= k:
max_val = -1
max_idx = -1
for i, x in enumerate(skills):
if x > max_val:
max_val = x
max_idx = i
return max_idx
l = 0
r = 1
t = 0
while l < n and r < n:
if skills[l] < skills[r]:
l = r
r = r + 1
t = 1
else:
r = r + 1
t += 1
if t >= k:
break
return l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32